package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.service.DamageListGoodsService;
import com.atguigu.jxc.vo.DamageSaveGoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author ONIE
 * @create 2021/11/26 2:10 上午
 */
@RestController
@RequestMapping("damageListGoods")
public class DamageListGoodsController {

	@Autowired
	private DamageListGoodsService damageListGoodsService;

	/**
	 * 保存报损单
	 * @param damageNumber
	 * @param damageSaveGoodsVo
	 * @return
	 */
	@PostMapping("save")
	public ServiceVO saveDamage(@RequestParam String damageNumber, DamageSaveGoodsVo damageSaveGoodsVo){

		damageListGoodsService.saveDamage(damageNumber,damageSaveGoodsVo);
		return new ServiceVO(100,"请求成功",null);
	}

	/**
	 * 报损单查询
	 * @param sTime
	 * @param eTime
	 * @return
	 */
	@PostMapping("list")
	public Map<String,Object> listDamage(@RequestParam String sTime,@RequestParam String eTime){
		List<DamageList> damageList= damageListGoodsService.listDamage(sTime,eTime);
		Map<String, Object> params = new HashMap<>();
		params.put("rows",damageList);
		return params;
	}

	/**
	 * 查询报损单商品信息
	 * @param damageListId
	 * @return
	 */
	@PostMapping("goodsList")
	public Map<String,Object> goodsList(@RequestParam Integer damageListId ){
		List<DamageListGoods> damageList= damageListGoodsService.goodsList(damageListId);
		Map<String, Object> params = new HashMap<>();
		params.put("rows",damageList);
		return params;
	}
}
